<?php

namespace App\Entity\Machine;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Base\Annotation\EntityInfo;
use App\Repository\Machine\MachineAgentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @EntityInfo(name="MachineAgent",cnName="代理商")
 * @ApiResource()
 * @ORM\Entity(repositoryClass=MachineAgentRepository::class)
 */
class MachineAgent
{
    /**
     * @Common(cnName="#",listType="text",editType="text")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"agent"})
     */
    private $id;

    /**
     * @Common(cnName="名称",listType="text",editType="text",width="300")
     * @ORM\Column(type="string", length=255)
     * @Groups({"agent"})
     */
    private $name;

    /**
     * @Common(cnName="联系人",listType="text",editType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $contact;

    /**
     * @Common(cnName="联系电话",listType="text",editType="text",width="150")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $phone;

    /**
     * @Common(cnName="地址",listType="text",editType="text",width="")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $address;

    /**
     * @Common(cnName="QQ",listType="text",editType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $qq;

    /**
     * @Common(cnName="微信",listType="text",editType="text",width="150")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $wx;

    /**
     * @Common(cnName="固话传真",listType="text",editType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $fax;

    /**
     * @Common(cnName="邮箱",listType="text",editType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"agent"})
     */
    private $email;

    /**
     * @Common(cnName="备注",listType="text",editType="art")
     * @ORM\Column(type="text", nullable=true)
     * @Groups({"agent"})
     */
    private $tips;

    /**
     * @ORM\OneToMany(targetEntity=Machine::class, mappedBy="agent")
     */
    private $machines;

    public function __construct()
    {
        $this->machines = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getContact(): ?string
    {
        return $this->contact;
    }

    public function setContact(?string $contact): self
    {
        $this->contact = $contact;

        return $this;
    }

    public function getPhone(): ?string
    {
        return $this->phone;
    }

    public function setPhone(?string $phone): self
    {
        $this->phone = $phone;

        return $this;
    }

    public function getAddress(): ?string
    {
        return $this->address;
    }

    public function setAddress(?string $address): self
    {
        $this->address = $address;

        return $this;
    }

    public function getQq(): ?string
    {
        return $this->qq;
    }

    public function setQq(?string $qq): self
    {
        $this->qq = $qq;

        return $this;
    }

    public function getWx(): ?string
    {
        return $this->wx;
    }

    public function setWx(?string $wx): self
    {
        $this->wx = $wx;

        return $this;
    }

    public function getFax(): ?string
    {
        return $this->fax;
    }

    public function setFax(?string $fax): self
    {
        $this->fax = $fax;

        return $this;
    }

    public function getEmail(): ?string
    {
        return $this->email;
    }

    public function setEmail(?string $email): self
    {
        $this->email = $email;

        return $this;
    }

    public function getTips(): ?string
    {
        return $this->tips;
    }

    public function setTips(?string $tips): self
    {
        $this->tips = $tips;

        return $this;
    }

    /**
     * @return Collection|Machine[]
     */
    public function getMachines(): Collection
    {
        return $this->machines;
    }

    public function addMachine(Machine $Machine): self
    {
        if (!$this->machines->contains($Machine)) {
            $this->machines[] = $Machine;
            $Machine->setAgent($this);
        }

        return $this;
    }

    public function removeMachine(Machine $Machine): self
    {
        if ($this->machines->contains($Machine)) {
            $this->machines->removeElement($Machine);
            // set the owning side to null (unless already changed)
            if ($Machine->getAgent() === $this) {
                $Machine->setAgent(null);
            }
        }

        return $this;
    }
}
